<?php
// +----------------------------------------------------------------------
// | zhanshop-marketing / Adapp.php    [ 2025/6/24 11:08 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2025 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\admin\v1\service\finder;

use zhanshop\Helper;
use zhanshop\server\Request;
use zhanshop\server\Response;

class Adapp extends BaseFinder
{
    protected $rowToolbar = [
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => '巨量监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=byte',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => '快手监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=kuaishou',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => '百度监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=baidu',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => '小米监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=xiaomi',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => '华为监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=huawei',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => 'vivo监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=vivo',
        ],
        [
            'event' => 'open',
            'ico' => '&#xe640;',
            'title' => 'oppo监测地址',
            'method' => '',
            'page' => './page/ad/adlisten-address.html?platform=oppo',
        ],
    ];

    public function adlisten(Request $request, Response $response)
    {
        $data = $request->validateRule([
            'app' => 'required',
            'platform' => 'required',
        ])->getData();
        $token = Helper::symmetryEncode(time().',a');
        $referer = $request->header('referer', 'https');
        $host = (strpos($referer, 'https:') === false ? 'http' : 'https').'://'.($request->header('host'));
        switch ($data['platform']){
            case "byte":
                $query = 'promotion_id=__PROMOTION_ID__&project_id=__PROJECT_ID__&promotion_name=__PROMOTION_NAME__&project_name=__PROJECT_NAME__&mid1=__MID1__&mid2=__MID2__&mid3=__MID3__&mid4=__MID4__&mid5=__MID5__&mid6=__MID6__&aid=__AID__&aid_name=__AID_NAME__&cid=__CID__&cid_name=__CID_NAME__&campaign_id=__CAMPAIGN_ID__&campaign_name=__CAMPAIGN_NAME__&ctype=__CTYPE__&advertiser_id=__ADVERTISER_ID__&csite=__CSITE__&convert_id=__CONVERT_ID__&request_id=__REQUEST_ID__&track_id=__TRACK_ID__&sl=__SL__&imei=__IMEI__&idfa=__IDFA__&idfa_md5=__IDFA_MD5__&android_id=__ANDROIDID__&oaid=__OAID__&oaid_md5=__OAID_MD5__&os=__OS__&mac=__MAC__&mac1=__MAC1__&ipv4=__IPV4__&ipv6=__IPV6__&ip=__IP__&ua=__UA__&geo=__GEO__&ts=__TS__&callback_param=__CALLBACK_PARAM__&callback_url=__CALLBACK_URL__&model=__MODEL__&union_site=__UNION_SITE__&caid=__CAID__&caid_md5=__CAID_MD5__&productid=__PRODUCTID&outerid=__OUTERID__';
                return [
                    '展示' => $host.'/v1/ad.listen/'.$data['app'].'/byte/show/'.$token.'?'.$query,
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/byte/click/'.$token.'?'.$query,
                    '播放' => $host.'/v1/ad.listen/'.$data['app'].'/byte/play/'.$token.'?'.$query,
                ];
                break;
            case "kuaishou":
                $query = 'adsocial_uid=__ADSOCIAL_UID__&adsocial_aid=__ADSOCIAL_AID__&accountid=__ACCOUNTID__&mission_id=__MISSION_ID__&order_id=__ORDER_ID__&cid=__CID__&did=__DID__&vid=__VID__&csite=__CSITE__&supplement_order_id=__SUPPLEMENT_ORDER_ID__&supplement_version=__SUPPLEMENT_VERSION__&traffic_source=__TRAFFIC_SOURCE__&ks_order_id=__KS_ORDER_ID__&photo_id=__PHOTO_ID__&eventid=__EVENTID__&requestid=__REQUESTID__&llsid=__LLSID__&imei2=__IMEI2__&imei3=__IMEI3__&oaid=__OAID__&oaid2=__OAID2__&idfa2=__IDFA2__&idfa3=__IDFA3__&kenyid_caa=__KENYID_CAA__&mac=__MAC__&mac2=__MAC2__&mac3=__MAC3__&androidid2=__ANDROIDID2__&androidid3=__ANDROIDID3__&ts=__TS__&ip=__IP__&ipv6=__IPV6__&ipv4=__IPV4__&fingerprint_time=__FINGERPRINT_TIME__&model=__MODEL__&os=__OS__&ua=__UA__&callback=__CALLBACK__';
                return [
                    '曝光' => $host.'/v1/ad.listen/'.$data['app'].'/kuaishou/show/'.$token.'?'.$query,
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/kuaishou/click/'.$token.'?'.$query,
                ];
                break;
            case "baidu":
                $query = 'aid=__IDEA_ID__&pid=__PLAN_ID__&uid=__UNIT_ID__&userid=__USER_ID__&click_id=__CLICK_ID__&idfa=__IDFA__&imei=__IMEI__&android_id=__ANDROIDID__&ip=__IP__&ua=__UA__&os=__OS__&ts=__TS__&ext_info=__EXT_INFO__&mac_md5=__MAC1__&mac=__MAC__&oaid=__OAID__&oaid_md5=__OAID_MD5__&comb_id=__COMBID__&size=__SIZE__&deeplink_url=__DEEPLINK_URL__&bd_vid=__BD_VID__&ext_info=__EXT_INFO__&callType=v2';
                return [
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/baidu/click/'.$token.'?'.$query,
                ];
                break;
            case "xiaomi":
                $query = 'response_validate=false&imei=__IMEI__&imei2=__IMEI2__&meid=__MEID__&oaid=__OAID__&click_time=__TS__&app_id=__APPID__&adid=__ADID__&campaign_id=__CAMPAIGNID__&customer_id=__CUSTOMERID__&callback=__CALLBACK__&sign=__SIGN__&expId=__EXPID__&ip=__IP__&ua=__UA__&androidId=__ANDROIDID__&adName=__ADNAME__&rtaExpId=__RTAEXPID__';
                return [
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/xiaomi/click/'.$token.'?'.$query,
                ];
                break;
            case "huawei":
                $query = 'aid=__AID__&aid_name=__AID_NAME__&app_id=__APP_ID__&app_name=__APP_NAME__&channel_name=__CHANNEL_NAME__&channel_id=__CHANNEL_ID__&group_name=__GROUP_NAME__&group_id=__GROUP_ID__&oaid=__OAID__&id_type=__ID_TYPE__&unique_id=__UNIQUE_ID__&action_type=__ACTION_TYPE__&ts=__TS__&callback=__CALLBACK__&sub_taskid=__SUB_TASKID__&rtaid=__RTAID__';
                return [
                    '展示' => $host.'/v1/ad.listen/'.$data['app'].'/huawei/show/'.$token.'?'.$query,
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/huawei/click/'.$token.'?'.$query,
                ];
                break;
            case "vivo":
                $query = 'hpkg_name=包名&src_type=APP&src_id=数据源';
                return [
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/vivo/click/'.$token.'?'.$query,
                ];
                break;
            case "oppo":
                $query = 'bundle=xx包名&ad=__ADID__&imei=__IMEI__&oaid=__OAID__&ts=__TS__&android_id=__ANDROIDID__&ip=__IP__&ua=$ua$&owner_id=$ownerid$&plan_id=$planid$&group_id=$groupid$';
                return [
                    '点击' => $host.'/v1/ad.listen/'.$data['app'].'/oppo/click/'.$token.'?'.$query,
                ];
                break;
        }
    }
}